home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX3_6.C < prev    next >
C/C++ Source or Header  |  1992-08-20  |  1KB  |  48 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/Complex.h>            // Include complex header file
  14.  
  15. #define FREQUENCY 346.87
  16. #define OMEGA (2 * 3.14159265358979323846 * FREQUENCY)
  17.  
  18. inline CoolComplex in_series (const CoolComplex& c1, const CoolComplex& c2) {
  19.   return (c1+c2);
  20. }
  21.  
  22. inline CoolComplex in_parallel (const CoolComplex& c1, const CoolComplex& c2) {
  23.   return ((c1.invert() + c2.invert()).invert ());
  24. }
  25.  
  26. inline CoolComplex resistor (double r) {
  27.   return CoolComplex (r);
  28. }
  29.  
  30. inline CoolComplex inductor (double i) {
  31.   return (CoolComplex (0.0, i * OMEGA));
  32. }
  33.  
  34. inline CoolComplex capacitor (double c) {
  35.   return (CoolComplex (0.0, -1.0 / (c * OMEGA)));
  36. }
  37.  
  38. int main (void) {
  39.   CoolComplex circuit;
  40.   circuit = in_series (resistor (1.0),
  41.                in_parallel (in_series (resistor (100.0),
  42.                            inductor (0.2)),
  43.                     in_parallel (capacitor (0.000001),
  44.                          resistor (10000000.0))));
  45.   cout << "Circuit impedence is " << circuit << " at frequency " << FREQUENCY << "\n";
  46.   return 0;                    // Exit with OK status
  47. }
  48.